package com.xindaoapp.henghua.db;

import java.util.Map;

import android.database.sqlite.SQLiteDatabase;

import com.xindaoapp.henghua.db.model.PropertyDao;
import com.xindaoapp.henghua.db.model.PropertyWithLabelDao;
import com.xindaoapp.henghua.db.model.ScanDatasDao;
import com.xindaoapp.henghua.db.model.SupervisionDao;
import com.xindaoapp.henghua.db.model.TagsDao;
import com.xindaoapp.henghua.db.model.TransportDatasDao;
import com.xindaoapp.henghua.entry.PropertyGatherInfo;
import com.xindaoapp.henghua.entry.PropertyLabelInfo;
import com.xindaoapp.henghua.entry.ScanData;
import com.xindaoapp.henghua.entry.SuperVisionInfo;
import com.xindaoapp.henghua.entry.TagsInfo;
import com.xindaoapp.henghua.entry.TransportDataInfo;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;

public class DaoSession extends AbstractDaoSession {
	private final PropertyDao propertyDao;
	private final PropertyWithLabelDao propertyWithLabelDao;
	private final ScanDatasDao scanDatasDao;
	private final SupervisionDao supervisionDao;
	private final TransportDatasDao transportDatasDao;
	private final TagsDao tagsDao;

	private final DaoConfig propertyConfig;
	private final DaoConfig propertyWithLabelDaoConfig;
	private final DaoConfig scanDatasDaoConfig;
	private final DaoConfig supervisionDaoConfig;
	private final DaoConfig transportDatasDaoConfig;
	private final DaoConfig tagsDaoConfig;

	public DaoSession(SQLiteDatabase db, IdentityScopeType type,
			Map<Class<? extends AbstractDao<?, ?>>, DaoConfig> daoConfigMap) {
		super(db);

		propertyConfig = daoConfigMap.get(PropertyDao.class).clone();
		propertyConfig.initIdentityScope(type);

		propertyWithLabelDaoConfig = daoConfigMap.get(PropertyWithLabelDao.class).clone();
		propertyWithLabelDaoConfig.initIdentityScope(type);

		scanDatasDaoConfig = daoConfigMap.get(ScanDatasDao.class).clone();
		scanDatasDaoConfig.initIdentityScope(type);

		supervisionDaoConfig = daoConfigMap.get(SupervisionDao.class).clone();
		supervisionDaoConfig.initIdentityScope(type);

		transportDatasDaoConfig = daoConfigMap.get(TransportDatasDao.class).clone();
		transportDatasDaoConfig.initIdentityScope(type);

		tagsDaoConfig = daoConfigMap.get(TagsDao.class).clone();
		tagsDaoConfig.initIdentityScope(type);

		propertyDao = new PropertyDao(propertyConfig, this);
		propertyWithLabelDao = new PropertyWithLabelDao(propertyWithLabelDaoConfig, this);
		scanDatasDao = new ScanDatasDao(scanDatasDaoConfig, this);
		supervisionDao = new SupervisionDao(supervisionDaoConfig, this);
		transportDatasDao = new TransportDatasDao(transportDatasDaoConfig, this);
		tagsDao = new TagsDao(tagsDaoConfig, this);

		registerDao(PropertyGatherInfo.class, propertyDao);
		registerDao(PropertyLabelInfo.class, propertyWithLabelDao);
		registerDao(ScanData.class, scanDatasDao);
		registerDao(SuperVisionInfo.class, supervisionDao);
		registerDao(TransportDataInfo.class, transportDatasDao);
		registerDao(TagsInfo.class, tagsDao);
	}

	public SupervisionDao getSuperVisionDao() {
		return supervisionDao;
	}

	public TransportDatasDao getTransportDataDao() {
		return transportDatasDao;
	}

	public PropertyDao getPropertyDao() {
		return propertyDao;
	}

	public PropertyWithLabelDao getPropertyWithLabelDao() {
		return propertyWithLabelDao;
	}

	public ScanDatasDao getScanDatasDao() {
		return scanDatasDao;
	}

	public TagsDao getTagsDao() {
		return tagsDao;
	}
}
